/**
 * Created by Administrator on 2015/11/14.
 */
$(function () {
    //渲染 top left
    commTemplUtil.initPage();
    commTemplUtil.setHeadCommNav(8);
    // 询价找车,验证规则.
    var myFormValiObj = $("#logistics_form").validate({
        rules: {
            loadpos: "required",
            unloadpos: "required",
            goodsdesc: "required",
            quantity: {
                required: true,
                digits: true
            },
            tel: {
                required: true,
                mobileCHINA: true,
            }

        },
        messages: {
            quantity: {
                digits: "请输入整数"
            },
            tel: {
                mobileCHINA: "请输入正确格式的手机号码",
            }
        }

    });

    // 帮我找车
    $("#find-truck-btn").on("click", function () {

        if(!COMM_DATA.topObj.userid) {
            // 未登录.
            var conf = {
                title : "注意",
                message : "请先登录!",
                ok_txt : "确定"
            };
            commTemplUtil.showErrorDialog(conf);
            return false;
        }

        var flag = myFormValiObj.form();

        var formObj = $("#logistics_form");

        if(!flag){
            // 验证失败
            return false;
        }

        var loadposVal = formObj.find("input[name='loadpos']").val() || '';
        var unloadposVal = formObj.find("input[name='unloadpos']").val() || '';
        var goodsdescVal = formObj.find("input[name='goodsdesc']").val() || '';
        var quantityVal = formObj.find("input[name='quantity']").val() || '';
        var telVal = formObj.find("input[name='tel']").val() || '';

        $.ajax({
            url : PAGE_CONFIG.requestUrl.addFindTruck,
            type : 'post',
            dataType : 'json',
            data : {
                loadpos : loadposVal, // 装车点
                unloadpos : unloadposVal, // 卸货点
                goodsdesc : goodsdescVal, // 货物名称
                quantity : quantityVal, // 数量
                tel : telVal, // 联系电话
                _token : COMM_DATA.csrfToken,
            },
            success : function (result) {
                var conf = {
                    title : "提示",
                    message : "提交成功!",
                    ok_txt : "确定"
                };
                commTemplUtil.showErrorDialog(conf);

            },
            error : function (result) {
                var conf = {
                    title : "提示",
                    message : "提交失败!",
                    ok_txt : "确定"
                };
                commTemplUtil.showErrorDialog(conf);
            }
        });

    });
});